package com.ada.lbs.v3.apps;

import java.util.List;

import com.ada.lbs.v3.domain.Poi;
import com.ada.lbs.v3.domain.PoiDetailState;
import com.ada.lbs.v3.domain.State;
import com.ada.lbs.v3.service.PoiService;
import com.ada.lbs.webservice.domain.BackPoi;
import com.ada.lbs.webservice.domain.Backs;
import com.ada.lbs.webservice.v2.PlaceService;

public class PoiApps {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		PoiService service = new PoiService();

//		Poi poi = new Poi();
//		poi.setAddress("陕西省西安市莲湖区二环路沿线商业经济带北院门115号");
//		poi.setTitle("陕西省西安市莲湖区");
//		// 108.950524,34.269067
//		poi.setLatitude(34.269067);
//		poi.setLongitude(108.950524);
//		poi.getData().put("name", "ada");
//		poi.setCoord_type(3);
//		
		
		PlaceService p = new PlaceService();
		p.setRegion("陕西");

		Backs b = p.searchByKey("1", 20, 1);
		if (b != null) {
			List<BackPoi> pois = b.getResults();
			for (BackPoi backPoi : pois) {
				System.out.println(backPoi);
				Poi poi=toPoi(backPoi);
				poi.setCoord_type(3);
				State s = service.add(poi);
				System.out.println(s);
			}
		}
	}

	public static Poi toPoi(BackPoi p) {
		Poi result = new Poi();
		result.setAddress(p.getAddress());
		result.setTitle(p.getName());
		if(p.getDetail_info()!=null){
			result.setTags(p.getDetail_info().getTag());
		}if(p.getLocation()!=null){
			result.setLatitude(p.getLocation().getLat());
			result.setLongitude(p.getLocation().getLng());
		}
		return result;
	}
}
